cur_path=$(pwd)

# detect_architecture()'s outputs params
Host_Architecture=""
# function: dectect architecture
detect_architecture() {
	OS=$(cat /etc/os-release | sed -n '/^ID=/p' | sed -e 's/"//g' -e 's/ID=//g')
	# aarch64-linux-gnu : /usr/lib/aarch64-linux-gnu
	# mips64el-linux-gnuabi64 : /usr/lib/mips64el-linux-gnuabi64
	# x86_64-linux-gnu : /usr/lib/x86_64-linux-gnu
	# mips64el-linux-gnu : /usr/lib/mips64el-linux-gnu
	Host_Architecture=`dpkg-architecture -qDEB_HOST_MULTIARCH`
	if test $OS = "nfsdesktop"
	then
		Host_Architecture=`uname -m`-linux-gnu
	fi
}

# call detect_architecture
detect_architecture

export LIBVA_DRIVER_NAME=raideonsi/nvidia/i965 # edit this, change it to what the actual vaapi driver name is
export GST_VAAPI_ALL_DRIVERS=1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$cur_path/lib/$Host_Architecture/ # load these libs in highest priority


echo "------------------------set envs------------------------"
echo "host architecture:     " $Host_Architecture
echo "LIBVA_DRIVER_NAME:     " $LIBVA_DRIVER_NAME
echo "GST_VAAPI_ALL_DRIVERS: " $GST_VAAPI_ALL_DRIVERS
echo "LD_LIBRARY_PATH:       " $LD_LIBRARY_PATH
echo ""

# gstreamer test
rm /tmp/gst_plugins.txt
$(gst-inspect-1.0 > /tmp/gst_plugins.txt)
echo "------------------------checking gstreamer------------------------"
echo "h264 plugins:" 
echo $(cat /tmp/gst_plugins.txt | grep h264)
echo ""
echo "h265 plugins:" 
echo $(cat /tmp/gst_plugins.txt | grep h265)
echo ""
echo "vaapi plugins:" 
echo $(cat /tmp/gst_plugins.txt | grep vaapi)
echo ""

cd $cur_path/bin/

echo "------------------------checking libs linking------------------------"
ldd ./spicy | grep spice
echo ""

echo "------------------------run spicy------------------------"
#./spicy --spice-debug --gst-debug=3,*decode*:7,*sink*:7,*vaapi*:7 2> /tmp/spicy.log
./spicy 

cd $cur_path

